package com.smartcodes.smartlockrpc.config;

/**
 * @ClassName OrderSystem
 * @Description TODO
 * @Author shuang669539827@163.com
 * @Date2019/3/22 19:06
 * @Version v1.0
 **/
public class OrderSystem implements Runnable {

    RedisLock redisLock = new RedisLock();

    @Override
    public void run() {
        if (redisLock.isLocked("orderId")) {
            System.out.println(Thread.currentThread().getId()+" 发现orderId被锁住  !");
//            System.out.println(Thread.currentThread().getId()+"发现orderId被锁住，我去解锁");
//            redisLock.unLock("orderId","10001");
        } else {
            try {
                boolean b = redisLock.tryLock("orderId", "10001");
                if (b) {
                    System.out.println(Thread.currentThread().getId() + "上锁成功！");
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }


    }
}
